package com.mao.action;

import com.mao.action.login.LoginAction;
import com.mao.model.user.User;
import com.mao.util.SessionHelper;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;

public class MyInterceptor implements Interceptor {

	private static final long serialVersionUID = -3185309251099739270L;

	public void destroy() {

	}

	public void init() {

	}

	public String intercept(ActionInvocation invocation) throws Exception {
		User su = SessionHelper.getSessionUser();

		// 用户没登录且验证权限的不通过，返回登录页面
		if (su == null && !(invocation.getAction().getClass() == LoginAction.class)) {
			return "sessionoutlogin";
		}

		try {
			return invocation.invoke();
		} catch (Exception ex) { // 异常捕获
			ex.printStackTrace();
		}
		return invocation.invoke();		
	}

}
